21 using namespace canGw;
89 static pthread_mutex_t
gwMutex = PTHREAD_MUTEX_INITIALIZER;
129 if ((NULL != cbChan1) && (NULL != cbChan2))
230 using namespace J2534;
231 unsigned long msgNum = 1;
234 J2534_ERROR_CODE passThruErr = STATUS_NOERROR;
247 passThruErr = PassThruWriteMsgs(idCh, txPassThruMsg, &msgNum,
TX_TIMEOUT);
248 pthread_mutex_unlock(&
gwMutex);
249 if (STATUS_NOERROR == passThruErr)
264 unsigned long interval)
266 using namespace J2534;
274 J2534_ERROR_CODE passThruErr = STATUS_NOERROR;
287 passThruErr = PassThruStartPeriodicMsg(idCh, txPassThruMsg, &idMsg, interval);
288 pthread_mutex_unlock(&
gwMutex);
289 if (STATUS_NOERROR == passThruErr)
306 using namespace J2534;
310 if ( STATUS_NOERROR == passThruErr)
327 using namespace J2534;
333 if (STATUS_NOERROR != passThruErr)
347 using namespace J2534;
352 static const unsigned long flagsCh1 = 0;
353 J2534_ERROR_CODE passThruErr = PassThruConnect(
gwParam.
idDevice, CAN, flagsCh1,
355 if (STATUS_NOERROR == passThruErr)
368 static const unsigned long flagsCh2 = PHYSICAL_CHANNEL;
369 J2534_ERROR_CODE passThruErr = PassThruConnect(
gwParam.
idDevice, CAN, flagsCh2,
371 if (STATUS_NOERROR == passThruErr)
391 using namespace J2534;
396 J2534_ERROR_CODE passThruErr = PassThruDisconnect(
gwParam.
idCh1);
397 if (STATUS_NOERROR == passThruErr)
410 J2534_ERROR_CODE passThruErr = PassThruDisconnect(
gwParam.
idCh2);
411 if (STATUS_NOERROR == passThruErr)
430 using namespace J2534;
433 J2534_ERROR_CODE passThruErr = PassThruIoctl(
gwParam.
idCh1, CLEAR_MSG_FILTERS, NULL, NULL);
434 if (STATUS_NOERROR != passThruErr)
438 passThruErr = PassThruIoctl(
gwParam.
idCh2, CLEAR_MSG_FILTERS, NULL, NULL);
439 if (STATUS_NOERROR != passThruErr)
445 PASSTHRU_MSG maskPassThruMsg;
446 PASSTHRU_MSG patternPassThruMsg;
447 J2534_ConnectFlags filterFlags;
449 memset(&maskPassThruMsg, 0,
sizeof(PASSTHRU_MSG));
450 maskPassThruMsg.ProtocolID = CAN;
451 filterFlags.bits.Can29BitId = 0;
452 maskPassThruMsg.TxFlags = filterFlags.value;
453 memset(&patternPassThruMsg, 0,
sizeof(PASSTHRU_MSG));
454 patternPassThruMsg.ProtocolID = CAN;
455 filterFlags.bits.Can29BitId = 0;
456 patternPassThruMsg.TxFlags = filterFlags.value;
458 passThruErr = PassThruStartMsgFilter(
gwParam.
idCh1, PASS_FILTER, &maskPassThruMsg,
460 if (STATUS_NOERROR != passThruErr)
464 passThruErr = PassThruStartMsgFilter(
gwParam.
idCh2, PASS_FILTER, &maskPassThruMsg,
466 if (STATUS_NOERROR != passThruErr)
495 threadParam->
active =
true;
497 int retVal = pthread_attr_init(&threadParam->
attr);
500 retVal = pthread_attr_setdetachstate(&threadParam->
attr, PTHREAD_CREATE_JOINABLE);
507 pthread_attr_destroy(&threadParam->
attr);
512 threadParam->
active =
false;
517 threadParam->
active =
false;
548 if (
false != threadParam->
active)
550 int retVal = pthread_cancel(threadParam->
id);
553 pthread_join(threadParam->
id, NULL);
554 threadParam->
active =
false;
570 using namespace J2534;
572 unsigned long msgNum;
574 static unsigned long RX_TIMEOUT = 0;
576 static const unsigned int THREAD_DELAY = 25 * 1000;
585 &msgNum, RX_TIMEOUT);
586 pthread_mutex_unlock(&
gwMutex);
587 if (STATUS_NOERROR == passThruErr)
591 else if (ERR_BUFFER_EMPTY == passThruErr)
599 usleep(THREAD_DELAY);
602 else if (
CHANNEL_2 == threadParam->gwChannel)
609 &msgNum, RX_TIMEOUT);
610 pthread_mutex_unlock(&
gwMutex);
611 if (STATUS_NOERROR == passThruErr)
615 else if (ERR_BUFFER_EMPTY == passThruErr)
623 usleep(THREAD_DELAY);
Definition of structure with CAN Gateway's parameters.
static ErrCode_e canGwConnectChannels()
Function connects CAN Gateway's channels.
Name of CAN Gateway's channel 2.
static ThreadParam_s threadParamCh1
Structure with thread parameters for Channel1.
static pthread_mutex_t gwMutex
Mutex for CAN Gateway's API.
ErrCode_e startPeriodic(Channel_e channel, J2534::PASSTHRU_MSG *txPassThruMsg, unsigned long interval)
Function starts CAN Gateway's periodic message.
unsigned long baudCh1
Baud rate of CAN CH1.
unsigned long baudCh2
Baud rate of CAN CH2.
unsigned long idDevice
ID of the device.
pthread_attr_t attr
Thread's attributes.
Name of CAN Gateway's channel 1.
Definition of structure with thread parameters.
static ErrCode_e canGwUninitRcvThread(Channel_e channel)
Function uninitializes receiving thread for given physical channel.
bool activeCh1
CAN CH1 active status.
unsigned long idCh1
ID of the CAN CH1.
Baudrate_e
Definition of CAN Gateway's baud rates.
static ErrCode_e canGwOpen()
Function opens CAN Gateway.
Header file for cangw.cpp.
ErrCode_e init(Baudrate_e baudChan1, Baudrate_e baudChan2, const RcvCb_t cbChan1, const RcvCb_t cbChan2)
Function initializes CAN Gateway device.
static GwParam_s gwParam
Structure with CAN device parameters.
static ErrCode_e canGwDisconnectChannels()
Function disconnects CAN Gateway's channels.
static unsigned long TX_TIMEOUT
Timeout for PassThruWriteMsgs() function.
static ErrCode_e canGwInitRcvThread(Channel_e channel)
Function initializes receiving thread for given physical channel.
Channel_e
Definition of CAN Gateway channels' names.
unsigned long idFilterCh1
ID of the filter for CAN CH1.
static RcvCb_t rcvCbCh2
Receive callback function for Channel 2.
bool active
Thread's status.
static const unsigned long BAUD_VAL_125KBPS
Value for baud rate = 125 kbps.
ErrCode_e
Definition of CAN Gateway's error codes.
static J2534::PASSTHRU_MSG * rxPassThruMsgCh1
Pointer to receive buffer with PASSTHRU messages for Channel 1.
static ErrCode_e canGwClose()
Function closes CAN Gateway.
static RcvCb_t rcvCbCh1
Receive callback function for Channel 1.
static ThreadParam_s threadParamCh2
Structure with thread parameters for Channel2.
void(* RcvCb_t)(const J2534::PASSTHRU_MSG *rxPassThruMsg, unsigned long rxMsgNum)
Definition of callback function for receive frames.
unsigned long idFilterCh2
ID of the filter for CAN CH2.
static const unsigned long BAUD_VAL_500KBPS
Value for baud rate = 500 kbps.
static ErrCode_e canGwSetFilters()
Function sets CAN Gateway's message filters.
unsigned long idCh2
ID of the CAN CH2.
static J2534::PASSTHRU_MSG * rxPassThruMsgCh2
Pointer to receive buffer with PASSTHRU messages for Channel 2.
static const unsigned long BAUD_VAL_1MBPS
Value for baud rate = 1 Mbps.
bool activeCh2
CAN CH2 active status.
static const unsigned int MAX_RX_MSGS
Maximum number of messages to receive.
Channel_e gwChannel
CAN Gateway's channel handled by thread.
ErrCode_e send(Channel_e channel, J2534::PASSTHRU_MSG *txPassThruMsg)
Function sends PASSTHRU frame via given channel.
static const unsigned long BAUD_VAL_250KBPS
Value for baud rate = 250 kbps.
static void * canGwRcvThreadFunc(void *params)
Function handles CAN Gateway's receiving threads.
ErrCode_e uninit()
Function uninitializes CAN Gateway device.